#pragma once
#include <TDF_Label.hxx>
#include "EditorFactory.h"
#include "AnyView.h"
#include "EditorData.h"

enum EditorState
{
	ES_NULL,
	ES_FINISHED,// the editor will finish
	ES_CONTINUE // the editor will keep working
};

enum EditorType
{
	ET_SHARE,
	ET_EXCLUSIVE
};

class CMenuContext
{
public:
	
};

//////////////////////////////////////////////////////////////////////////
class CRenderEngine;
class CAnyView;
class CShapeInfo;
class IEditorViewer;

class GEOMDBAPI CAnyEditor
{
public:
	CAnyEditor(void);
	virtual ~CAnyEditor(void) = 0;
	virtual void Initialize(CAnyView* pView);
	virtual EditorState Start(void);
	virtual void Preview();
	virtual void Finish(void);
	virtual void Abort(void);

	// Mouse messages
	// default state ES_CONTINUE
	virtual EditorState OnLButtonDown(UINT nFlags, long x, long y);
	virtual EditorState OnLButtonUp(UINT nFlags, long x, long y);
	virtual void		OnMouseMove(UINT nFlags, long x, long y);
	virtual EditorState OnRButtonDown(UINT nFlags, long x, long y);
	virtual EditorState OnRButtonUp(UINT nFlags, long x, long y);
	virtual EditorState OnMouseWheel(UINT nFlags, short zDelta,long x, long y);

	// Key messages
	// default state ES_CONTINUE
	virtual EditorState OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	virtual EditorState OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	virtual EditorState OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);

	// Context menu
	virtual void OnContextMenu(const CMenuContext& contextMenu);
	CAnyView* GetView(void){return m_pView;}
	CRenderEngine* GetRender(void);
	TDF_Label	GetRootLabel();
	virtual EditorType Type(){return ET_EXCLUSIVE;}
	virtual CShapeInfo* GetShapeInfo(){return NULL;}
	
	//
	virtual void OnChangeParam(UINT nID);
	void SetEditorViewer(IEditorViewer* pViewer);

	// extra data
	void SetData(const CEditorData& edData){m_Data = edData;}
	CEditorData& GetData(void){return m_Data;}
protected:
	CAnyView*		m_pView;
	IEditorViewer*	m_pEditorViewer;
	CEditorData		m_Data;
};

//////////////////////////////////////////////////////////////////////////

template <typename TBase>
class TZoomWithWheel : public TBase
{
public:
	virtual EditorState OnMouseWheel(UINT nFlags, short zDelta,long x, long y)
	{
		GetView()->Zoom(x, y, x+zDelta/10, y+zDelta/10);

		return ES_CONTINUE;
	}
};

class GEOMDBAPI CShareEditorBase : public CAnyEditor
{
public:
	virtual EditorType Type(){return ET_SHARE;}

	virtual ~CShareEditorBase(){};
};


class GEOMDBAPI IEditorViewer
{
public:
	virtual ~IEditorViewer(){}
	virtual void OnParamChanged(UINT nID) = 0;
	virtual void OnChangeParam(UINT nID) = 0;
};